﻿using System;

namespace Ndns.Packet.Abstractions.ResourceRecords
{
    public sealed class DnsResourceRecordMX : DnsResourceRecord
    {

        public override DnsHostName HostName { get; set; }
        public override DnsRecordType Type { get => DnsRecordType.MX; protected set => throw new NotSupportedException(); }
        public override DnsClass Class { get; protected set; }

        /// <summary>
        /// 表示应答中的优先级记录。
        /// </summary>
        public ushort Preference { get; set; }

        /// <summary>
        /// 表示应答中的域名记录。
        /// </summary>
        public DnsHostName MXHostName { get; set; }

        public DnsResourceRecordMX(DnsHostName hostName, DnsClass c, uint ttl)
            : base(hostName, c, ttl)
        {
        }

        /// <summary>
        /// 根据相关信息构造DnsResourceRecordMX实例。
        /// </summary>
        /// <param name="hostName">DNS应答的主机名信息。</param>
        /// <param name="c">DNS应答的类别。</param>
        /// <param name="ttl">DNS应答的超时时间。</param>
        /// <param name="mxHostName">DNS应答的数据。</param>
        public DnsResourceRecordMX(DnsHostName hostName, DnsClass c, uint ttl, ushort preferenceLevel, DnsHostName mxHostName)
            : base(hostName, c, ttl)
        {
            Preference = preferenceLevel;
            MXHostName = mxHostName;
        }

        public override DnsResourceRecord Clone()
        {
            return new DnsResourceRecordMX(HostName, Class, TTL, Preference, MXHostName);
        }
    }
}
